{
"posts": [
{ "id": 1, "title": "json-server", "author": "typicode" }
],
"comments": [
{ "id": 1, "body": "some comment", "postId": 1 }
],
"profile": { "name": "typicode" }
}
json-server --watch db.json --port 3004
"liveServer.settings.ignoreFiles":[
"db.json" // 加上
],
const headers = {
Host: 'localhost:3000',
'content-length': '19',
Connection: 'keep-alive',
'accept-encoding': 'gzip, deflate',
'User-Agent': 'PostmanRuntime/7.15.0',
// 正常的 request 不需要此 token
'Postman-Token': 'b0a75f76-8b4a-4a9f-b398-9f7a1cd7bf51,9a5e1c49-89ed-4e7d-b3d3-30bf3ab8ab5b',
}
Content-Type: application/x-www-form-urlencoded;charset=utf-8
url/?title=test&name=Tom
在 Send按鈕的下面有個 Code 選擇 JavaScript
const data = { users: [] }
// Create 1000 users
for (let i = 0; i < 1000; i++) { data.users.push({ id: i, name: `user${i}` }) }
return data
{
"新的路徑": "預設的路徑",
// 用 /api/posts 取代原本的 /posts
"/api/*": "/$1",
// 用 /api/posts/1 取代 /posts/1
"/:resource/:id/show": "/:resource/:id",
// 用 posts/html 取代 /posts?category=html
"/posts/:category": "/posts?category=:category",
// 用 articles?id=1 取代 /posts/1
"/articles\\?id=:id": "/posts/:id"
}
// url?屬性=值&另屬性=值
GET /posts?author.name=Tim&year=1800
// 支援 RegExp
GET /posts?title_like=server
GET /posts?_page=7
GET /posts?_page=7&_limit=20
GET /posts?views_gte=10&views_lte=20
GET /posts?id_ne=1
GET /posts?title_like=server
GET /posts?_sort=views&_order=asc
// 選擇一數性並排序
GET /posts/1/comments?_sort=votes&_order=asc
// 多個屬性排序
GET /posts?_sort=user,views&_order=desc,asc
GET /posts?_start=20&_end=30
GET /posts/1/comments?_start=20&_end=30
GET /posts/1/comments?_start=20&_limit=10